package mytomcat.servlet;

import mytomcat.anno.Servlet;
import mytomcat.core.MyRequest;
import mytomcat.core.MyResponse;
import mytomcat.dto.ServletInfo;
import mytomcat.servlet.base.MyServlet;

import java.io.IOException;

/**
 * <ul>
 * <li>Title:  HelloWorldServlet</li>
 * <li>Description: TODO </li>
 * <li>Copyright: Copyright (c) 2018</li>
 *
 * </ul>
 *
 * @author swc
 * @version     V1.0
 * @date 2020/4/20 0020 上午 9:53
 */
@Servlet
public class DataGridServlet extends MyServlet {

    private static String jsonStr ="{\n" +
            "\t\"code\": 0,\n" +
            "\t\"msg\": \"\",\n" +
            "\t\"count\": 1000,\n" +
            "\t\"data\": [{\n" +
            "\t\t\"id\": 10000,\n" +
            "\t\t\"username\": \"user-0\",\n" +
            "\t\t\"sex\": \"女\",\n" +
            "\t\t\"city\": \"城市-0\",\n" +
            "\t\t\"sign\": \"签名-0\",\n" +
            "\t\t\"experience\": 255,\n" +
            "\t\t\"logins\": 24,\n" +
            "\t\t\"wealth\": 82830700,\n" +
            "\t\t\"classify\": \"作家\",\n" +
            "\t\t\"score\": 57\n" +
            "\t}, {\n" +
            "\t\t\"id\": 10001,\n" +
            "\t\t\"username\": \"user-1\",\n" +
            "\t\t\"sex\": \"男\",\n" +
            "\t\t\"city\": \"城市-1\",\n" +
            "\t\t\"sign\": \"签名-1\",\n" +
            "\t\t\"experience\": 884,\n" +
            "\t\t\"logins\": 58,\n" +
            "\t\t\"wealth\": 64928690,\n" +
            "\t\t\"classify\": \"词人\",\n" +
            "\t\t\"score\": 27\n" +
            "\t}, {\n" +
            "\t\t\"id\": 10002,\n" +
            "\t\t\"username\": \"user-2\",\n" +
            "\t\t\"sex\": \"女\",\n" +
            "\t\t\"city\": \"城市-2\",\n" +
            "\t\t\"sign\": \"签名-2\",\n" +
            "\t\t\"experience\": 650,\n" +
            "\t\t\"logins\": 77,\n" +
            "\t\t\"wealth\": 6298078,\n" +
            "\t\t\"classify\": \"酱油\",\n" +
            "\t\t\"score\": 31\n" +
            "\t}, {\n" +
            "\t\t\"id\": 10003,\n" +
            "\t\t\"username\": \"user-3\",\n" +
            "\t\t\"sex\": \"女\",\n" +
            "\t\t\"city\": \"城市-3\",\n" +
            "\t\t\"sign\": \"签名-3\",\n" +
            "\t\t\"experience\": 362,\n" +
            "\t\t\"logins\": 157,\n" +
            "\t\t\"wealth\": 37117017,\n" +
            "\t\t\"classify\": \"诗人\",\n" +
            "\t\t\"score\": 68\n" +
            "\t}, {\n" +
            "\t\t\"id\": 10004,\n" +
            "\t\t\"username\": \"user-4\",\n" +
            "\t\t\"sex\": \"男\",\n" +
            "\t\t\"city\": \"城市-4\",\n" +
            "\t\t\"sign\": \"签名-4\",\n" +
            "\t\t\"experience\": 807,\n" +
            "\t\t\"logins\": 51,\n" +
            "\t\t\"wealth\": 76263262,\n" +
            "\t\t\"classify\": \"作家\",\n" +
            "\t\t\"score\": 6\n" +
            "\t}, {\n" +
            "\t\t\"id\": 10005,\n" +
            "\t\t\"username\": \"user-5\",\n" +
            "\t\t\"sex\": \"女\",\n" +
            "\t\t\"city\": \"城市-5\",\n" +
            "\t\t\"sign\": \"签名-5\",\n" +
            "\t\t\"experience\": 173,\n" +
            "\t\t\"logins\": 68,\n" +
            "\t\t\"wealth\": 60344147,\n" +
            "\t\t\"classify\": \"作家\",\n" +
            "\t\t\"score\": 87\n" +
            "\t}, {\n" +
            "\t\t\"id\": 10006,\n" +
            "\t\t\"username\": \"user-6\",\n" +
            "\t\t\"sex\": \"女\",\n" +
            "\t\t\"city\": \"城市-6\",\n" +
            "\t\t\"sign\": \"签名-6\",\n" +
            "\t\t\"experience\": 982,\n" +
            "\t\t\"logins\": 37,\n" +
            "\t\t\"wealth\": 57768166,\n" +
            "\t\t\"classify\": \"作家\",\n" +
            "\t\t\"score\": 34\n" +
            "\t}, {\n" +
            "\t\t\"id\": 10007,\n" +
            "\t\t\"username\": \"user-7\",\n" +
            "\t\t\"sex\": \"男\",\n" +
            "\t\t\"city\": \"城市-7\",\n" +
            "\t\t\"sign\": \"签名-7\",\n" +
            "\t\t\"experience\": 727,\n" +
            "\t\t\"logins\": 150,\n" +
            "\t\t\"wealth\": 82030578,\n" +
            "\t\t\"classify\": \"作家\",\n" +
            "\t\t\"score\": 28\n" +
            "\t}, {\n" +
            "\t\t\"id\": 10008,\n" +
            "\t\t\"username\": \"user-8\",\n" +
            "\t\t\"sex\": \"男\",\n" +
            "\t\t\"city\": \"城市-8\",\n" +
            "\t\t\"sign\": \"签名-8\",\n" +
            "\t\t\"experience\": 951,\n" +
            "\t\t\"logins\": 133,\n" +
            "\t\t\"wealth\": 16503371,\n" +
            "\t\t\"classify\": \"词人\",\n" +
            "\t\t\"score\": 14\n" +
            "\t}, {\n" +
            "\t\t\"id\": 10009,\n" +
            "\t\t\"username\": \"user-9\",\n" +
            "\t\t\"sex\": \"女\",\n" +
            "\t\t\"city\": \"城市-9\",\n" +
            "\t\t\"sign\": \"签名-9\",\n" +
            "\t\t\"experience\": 484,\n" +
            "\t\t\"logins\": 25,\n" +
            "\t\t\"wealth\": 86801934,\n" +
            "\t\t\"classify\": \"词人\",\n" +
            "\t\t\"score\": 75\n" +
            "\t}]\n" +
            "}\n";


    @Override
    public void doGet(MyRequest myRequest, MyResponse myResponse, ServletInfo servletInfo) {
        doHand(myRequest,myResponse);
    }



    public void doPost(MyRequest myRequest, MyResponse myResponse, ServletInfo servletInfo) {
        doHand(myRequest,myResponse);
    }


    private void doHand(MyRequest myRequest,MyResponse myResponse) {
        try {
            myResponse.writeJSon(jsonStr);
        }catch (IOException ex){
            ex.printStackTrace();
        }
    }
}
